<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class NewhouseLayout extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'newhouse_layout';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'htype_text',
        'vtype_text',
        'atype_text',
        'stype_text',
        'otype_text',
        'recommend_text',
        'flag_text'
    ];



    public function getHtypeList()
    {
        return ['0' => __('Htype 0'), '1' => __('Htype 1'), '2' => __('Htype 2'), '3' => __('Htype 3'), '4' => __('Htype 4'), '5' => __('Htype 5')];
    }

    public function getVtypeList()
    {
        return ['0' => __('Vtype 0'), '1' => __('Vtype 1'), '2' => __('Vtype 2'), '3' => __('Vtype 3'), '4' => __('Vtype 4')];
    }

    public function getAtypeList()
    {
        return ['0' => __('Atype 0'), '1' => __('Atype 1'), '2' => __('Atype 2'), '3' => __('Atype 3')];
    }

    public function getStypeList()
    {
        return ['0' => __('Stype 0'), '1' => __('Stype 1'), '2' => __('Stype 2'), '3' => __('Stype 3'), '4' => __('Stype 4'), '5' => __('Stype 5'), '6' => __('Stype 6'), '7' => __('Stype 7')];
    }

    public function getOtypeList()
    {
        return ['0' => __('Otype 0'), '1' => __('Otype 1'), '2' => __('Otype 2'), '3' => __('Otype 3')];
    }

    public function getRecommendList()
    {
        return ['0' => __('Recommend 0'), '1' => __('Recommend 1')];
    }

    public function getFlagList()
    {
        return ['0' => __('Flag 0'), '1' => __('Flag 1')];
    }


    public function getHtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['htype']) ? $data['htype'] : '');
        $list = $this->getHtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getVtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['vtype']) ? $data['vtype'] : '');
        $list = $this->getVtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['atype']) ? $data['atype'] : '');
        $list = $this->getAtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stype']) ? $data['stype'] : '');
        $list = $this->getStypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['otype']) ? $data['otype'] : '');
        $list = $this->getOtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['recommend']) ? $data['recommend'] : '');
        $list = $this->getRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFlagTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['flag']) ? $data['flag'] : '');
        $list = $this->getFlagList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->belongsTo('\app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function newhousestructure()
    {
        return $this->belongsTo('NewhouseStructure', 'structure_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
